package com.zelix;

import java.io.IOException;
import java.io.Reader;

public class a5
{

    int a;
    int b;
    int c;
    public int d;
    protected int e[];
    protected int f[];
    protected int g;
    protected int h;
    protected boolean i;
    protected boolean j;
    protected Reader k;
    protected char l[];
    protected int m;
    protected int n;

    public a5(Reader reader, int i1, int j1)
    {
        this(reader, i1, j1, 4096);
    }

    public a5(Reader reader, int i1, int j1, int k1)
    {
        d = -1;
        g = 0;
        h = 1;
        i = false;
        j = false;
        m = 0;
        n = 0;
        k = reader;
        h = i1;
        g = j1 - 1;
        b = a = k1;
        l = new char[k1];
        e = new int[k1];
        f = new int[k1];
    }

    public char a()
        throws IOException
    {
        c = -1;
        char c1 = h();
        c = d;
        return c1;
    }

    protected void a(boolean flag)
    {
label0:
        {
            char ac[] = new char[a + 2048];
            int ai[] = new int[a + 2048];
            int ai1[] = new int[a + 2048];
            try
            {
                if(flag)
                {
                    System.arraycopy(l, c, ac, 0, a - c);
                    System.arraycopy(l, 0, ac, a - c, d);
                    l = ac;
                    System.arraycopy(e, c, ai, 0, a - c);
                    System.arraycopy(e, 0, ai, a - c, d);
                    e = ai;
                    System.arraycopy(f, c, ai1, 0, a - c);
                    System.arraycopy(f, 0, ai1, a - c, d);
                    f = ai1;
                    m = d += a - c;
                    if(si.g == 0)
                        break label0;
                }
                System.arraycopy(l, c, ac, 0, a - c);
                l = ac;
                System.arraycopy(e, c, ai, 0, a - c);
                e = ai;
                System.arraycopy(f, c, ai1, 0, a - c);
                f = ai1;
                m = d -= c;
            }
            catch(Throwable throwable)
            {
                throw new Error(throwable.getMessage());
            }
        }
        a += 2048;
        b = a;
        c = 0;
    }

    protected void b()
        throws IOException
    {
label0:
        {
            int j1 = si.g;
            if(m != b)
                break label0;
            if(b == a)
            {
                if(c > 2048)
                {
                    d = m = 0;
                    b = c;
                    if(j1 == 0)
                        break label0;
                }
                if(c < 0)
                {
                    d = m = 0;
                    if(j1 == 0)
                        break label0;
                }
                a(false);
                if(j1 == 0)
                    break label0;
            }
            if(b > c)
            {
                b = a;
                if(j1 == 0)
                    break label0;
            }
            if(c - b < 2048)
            {
                a(true);
                if(j1 == 0)
                    break label0;
            }
            b = c;
        }
        int i1;
        try
        {
            if((i1 = k.read(l, m, b - m)) == -1)
            {
                k.close();
                throw new IOException();
            } else
            {
                m += i1;
                return;
            }
        }
        catch(IOException ioexception)
        {
            d--;
            b(0);
            if(c == -1)
                c = d;
            throw ioexception;
        }
    }

    public String c()
    {
        if(d >= c)
            return new String(l, c, (d - c) + 1);
        else
            return new String(l, c, a - c) + new String(l, 0, d + 1);
    }

    public char[] a(int i1)
    {
        char ac[];
label0:
        {
            ac = new char[i1];
            if(d + 1 >= i1)
            {
                System.arraycopy(l, (d - i1) + 1, ac, 0, i1);
                if(si.g == 0)
                    break label0;
            }
            System.arraycopy(l, a - (i1 - d - 1), ac, 0, i1 - d - 1);
            System.arraycopy(l, 0, ac, i1 - d - 1, d + 1);
        }
        return ac;
    }

    protected void a(char c1)
    {
        int i1;
label0:
        {
            i1 = si.g;
            g++;
            if(j)
            {
                j = false;
                h += g = 1;
                if(i1 == 0)
                    break label0;
            }
            if(!i)
                break label0;
            i = false;
            if(c1 == '\n')
            {
                j = true;
                if(i1 == 0)
                    break label0;
            }
            h += g = 1;
        }
        switch(c1)
        {
        case 11: // '\013'
        case 12: // '\f'
        default:
            break;

        case 13: // '\r'
            i = true;
            if(i1 == 0)
                break;
            // fall through

        case 10: // '\n'
            j = true;
            if(i1 == 0)
                break;
            // fall through

        case 9: // '\t'
            g--;
            g += 8 - (g & 7);
            break;
        }
        e[d] = h;
        f[d] = g;
    }

    public void b(int i1)
    {
        n += i1;
        if((d -= i1) < 0)
            d += a;
    }

    public int d()
    {
        return f[c];
    }

    public int e()
    {
        return e[c];
    }

    public int f()
    {
        return f[d];
    }

    public int g()
    {
        return e[d];
    }

    public char h()
        throws IOException
    {
        if(n > 0)
        {
            n--;
            if(++d == a)
                d = 0;
            return l[d];
        }
        if(++d >= m)
            b();
        char c1 = l[d];
        a(c1);
        return c1;
    }
}